<?php
/**
 * 充值相关接口
 */
namespace App\Controller;

use Think\Controller;

class RechargeController extends Controller {
    protected $m_recharge;
    public  $page_num = 10;
    public function _initialize() {
	    $this->m_recharge = D("Admin/Recharge");
//	    $this->m_card = D("Admin/Card");
//	    $this->m_logistics = D("Admin/Logistics");
    }

    /**
     * 卡充值列表
     */
    public function lists() {
        $page_num = I("post.page_num",1);
        $card_number = I("post.card_number");
        if(empty($card_number)){
            $this->errorReturn("请先输入卡号！");
        }
        $page_num = $page_num<0?1:$page_num;
        $where = ['r.model'=>2,'c.number'=>$card_number];
        $list = $this->m_recharge->get_card_list($where, "r.create_time DESC", ($page_num-1)*$this->page_num, $this->page_num);
        $this->successReturn($list);
    }

    /**
     * 充值详情
     */
    public function detail(){
        $detail_id = I("post.detail_id");
        if(empty($detail_id)){
            $this->errorReturn("请输入充值记录详情ID");
        }
        $where = ['r.model'=>2,'r.id'=>$detail_id];
        $item = $this->m_recharge->get_card_recharge_one($where, "r.create_time DESC");
        if(empty($item)){
            $this->errorReturn("充值记录不存在！");
        }else{
            $this->successReturn($item);
        }

    }


    public function rechargeupdate(){
        $recharge_number = I("post.recharge_number");
        $result =  $this->m_recharge->update_status($recharge_number);
        if ($result) {
            push_recharge($result['id']);
            exit(json_return('1','',array('detail_id'=>$result['id'])));
            // $this->success("充值成功！");
        } else {
            exit(json_return('0','回调失败！'));
        }
    }
}

